package com.ruoyi.web.controller.contest;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import com.ruoyi.contest.domain.TAnalyze;
import com.ruoyi.contest.service.ITAnalyzeService;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据分析Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/contest/tanalyze")
public class TAnalyzeController extends BaseController
{
    private final ITAnalyzeService tAnalyzeService;

    @Autowired
    private ITAnalyzeService analyzeService;

    /**
     * 查询数据分析列表
     */
    @PreAuthorize("@ss.hasPermi('contest:tanalyze:list')")
    @GetMapping("/list")
    public List list(String param)
    {
        List list = analyzeService.selectCountAndClassify(param);
        System.err.println("controller:"+list.get(0));
        return list;

    }

    /**
     * 导出数据分析列表
     */
    @PreAuthorize("@ss.hasPermi('contest:tanalyze:export')")
    @Log(title = "数据分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAnalyze tAnalyze)
    {
        List<TAnalyze> list = tAnalyzeService.selectTAnalyzeList(tAnalyze);
        ExcelUtil<TAnalyze> util = new ExcelUtil<TAnalyze>(TAnalyze.class);
        util.exportExcel(response, list, "数据分析数据");
    }

    /**
     * 获取数据分析详细信息
     */
    @PreAuthorize("@ss.hasPermi('contest:tanalyze:query')")
    @GetMapping(value = "/{analyzeId}")
    public AjaxResult getInfo(@PathVariable("analyzeId") Long analyzeId)
    {
        return success(tAnalyzeService.getById(analyzeId));
    }

    /**
     * 新增数据分析
     */
    @PreAuthorize("@ss.hasPermi('contest:tanalyze:add')")
    @Log(title = "数据分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAnalyze tAnalyze)
    {
        return toAjax(tAnalyzeService.save(tAnalyze));
    }

    /**
     * 修改数据分析
     */
    @PreAuthorize("@ss.hasPermi('contest:tanalyze:edit')")
    @Log(title = "数据分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAnalyze tAnalyze)
    {
        return toAjax(tAnalyzeService.updateById(tAnalyze));
    }

    /**
     * 删除数据分析
     */
    @PreAuthorize("@ss.hasPermi('contest:tanalyze:remove')")
    @Log(title = "数据分析", businessType = BusinessType.DELETE)
    @DeleteMapping("/{analyzeIds}")
    public AjaxResult remove(@PathVariable Long[] analyzeIds)
    {
        return toAjax(tAnalyzeService.removeByIds(Arrays.asList(analyzeIds)));
    }


}
